package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.mappers.SoulOptionsContentMapper;
import com.tanhua.model.domain.SoulOptionsContent;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Description：test
 * @Create by： 张会豪
 * @Date：2021/11/8 9:42
 */
@DubboService
public class SoulOptionsContentApiImpl implements SoulOptionsContentApi {

    @Autowired
    private SoulOptionsContentMapper soulOptionsContentMapper;

    //根据soulTestQuestionId，查询SoulOptionsContent对象集合
    public List<SoulOptionsContent> findById(Long testQuestionId) {
        LambdaQueryWrapper<SoulOptionsContent> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SoulOptionsContent::getTestQuestionId, testQuestionId);
        List<SoulOptionsContent> soulOptionsContents = soulOptionsContentMapper.selectList(queryWrapper);
        //给实体类中option赋值
        for (SoulOptionsContent soulOptionsContent : soulOptionsContents) {
            soulOptionsContent.setOption(soulOptionsContent.getOptionContent());
        }
        return soulOptionsContents;
    }

    //调用SoulOptionsContentApi在SoulOptionsContent表中查询对象，返回
    public SoulOptionsContent findByIds(Long optionId, Long questionId) {
        LambdaQueryWrapper<SoulOptionsContent> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SoulOptionsContent::getId, optionId);
        queryWrapper.eq(SoulOptionsContent::getTestQuestionId, questionId);
        return soulOptionsContentMapper.selectOne(queryWrapper);
    }
}
